<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

<!-- layui -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/layui/css/layui.css">
<link rel="stylesheet" type="text/css" href="/layer/layer.css" />
<script src="/layer/jquery-3.6.0.min.js"></script>
<script src="/layer/layer.js"></script>
<script src="${pageContext.request.contextPath }/layui/layui.js"></script>
<!-- layui -->

<script language="javascript" type="text/javascript"
	src="/js/check_addEmployee.js"></script>

</head>

<body>
	<fieldset class="layui-elem-field">
		<legend>员工信息修改</legend>
		<div class="layui-field-box">
			<div class="layui-form"></div>
		</div>
	</fieldset>
	<form id="formId" style="width: 800px; padding-top: 20px"
		class="layui-form" action="editEmployeeInfo" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">员工编号</label>
			<div class="layui-input-block">
				<input type="text" name="comployeeNo"
					value="${employee.comployeeNo}" required lay-verify="required"
					placeholder="请输入内容" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-block">
				<input type="text" name="comployeeName"
					value="${employee.comployeeName}" required lay-verify="required"
					placeholder="请输入内容" autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block">
				<input type="radio" name="sex" value="男" title="男"
					<c:if test="${employee.sex=='男'}">checked="checked"</c:if>>
				<input type="radio" name="sex" value="女" title="女"
					<c:if test="${employee.sex=='女'}">checked="checked"</c:if>>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">年龄</label>
			<div class="layui-input-block">
				<input type="number" name="age" value="${employee.age}"
					placeholder="请输入内容" autocomplete="off" class="layui-input">

			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">所在部门</label>
			<div class="layui-input-block">
				<select name="dept">
					<option value="${employee.dept}">${employee.dept}</option>
					<c:forEach items="${departments}" var="department">
						<option value="${department.dept}">${department.dept}</option>
					</c:forEach>
				</select>

			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">现任职务</label>
			<div class="layui-input-block">
				<input type="text" name="profession" value="${employee.profession}"
					required lay-verify="required" placeholder="请输入内容"
					autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">家庭地址</label>
			<div class="layui-input-block">
				<input type="text" name="address" value="${employee.address}"
					lay-verify="required" placeholder="请输入内容" autocomplete="off"
					class="layui-input">

			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">联系方式</label>
			<div class="layui-input-block">
				<input type="text" name="phone" value="${employee.phone}" required
					lay-verify="required" placeholder="请输入内容" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">员工状态</label>
			<div class="layui-input-block">
				<select name="comployeeStatus">
					<option value="在职"
						<c:if test="${employee.comployeeStatus=='在职'}">selected</c:if>>在职</option>
					<option value="休假"
						<c:if test="${employee.comployeeStatus=='休假'}">selected</c:if>>休假</option>
					<option value="离职"
						<c:if test="${employee.comployeeStatus=='离职'}">selected</c:if>>离职</option>
				</select>
			</div>
		</div>


		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				<button type="button" onclick="window.history.back();"
					class="layui-btn layui-btn-primary">返回上一级</button>
			</div>
		</div>

	</form>

	<script>
		var $;
		layui.use([ 'form', 'laydate', 'jquery' ], function() {
			var form = layui.form;
			var laydate = layui.laydate;
			$ = layui.jquery;

			//监听提交
			form.on('submit(formDemo)', function(data) {
				console.log(data.field);
				//Ajax提交
				$.ajax({
					url : "/editEmployeeInfo",
					context : document.body,
					type : 'post',
					data : JSON.stringify(data.field),
					contentType : 'application/json',
					success : function(result) {	
						if (result == 'error') {
							layer.msg('修改失败', {
								time : 1000, //X s后自动关闭
							});
						} else {
							layer.msg('修改成功! 即将跳转上一页...', {
								time : 1000, //2s后自动关闭
							});
							setTimeout(function() {
								window.location.href = result;
							}, 1000);
						}
					}
				});

				return false;
			});

		});
	</script>

</body>
</html>
